#include "builder.h"
#include <iostream>

Product::Product()
{
    std::cout << "创建产品实例" << std::endl;
}

Product::~Product()
{
    std::cout << "释放产品实例" << std::endl;
}

void Product::SetParamA()
{
    std::cout << "设置参数A..." << std::endl;
}

void Product::SetParamB()
{
    std::cout << "设置参数B..." << std::endl;
}

void Product::SetParamC()
{
    std::cout << "设置参数C..." << std::endl;
}

void Product::Show()
{
    std::cout << "产品展示!" << std::endl;
}

AbstractBuilder::AbstractBuilder()
{}

AbstractBuilder::~AbstractBuilder()
{}

ConcreteBuilder::ConcreteBuilder()
{
    this->product_ = NULL;
    std::cout << "创建建造者实例" << std::endl;
}

ConcreteBuilder::~ConcreteBuilder()
{
    if (NULL != this->product_)
    {
        delete this->product_;
        this->product_ = NULL;
    }
    std::cout << "释放建造者实例" << std::endl;
}

Product* ConcreteBuilder::CreateProduct()
{
    std::cout << "创建产品空壳..." << std::endl;
    if (NULL == this->product_)
    {
        this->product_ = new Product();
    }
    
    return this->product_;
}

void ConcreteBuilder::BuildParamA()
{
    std::cout << "正在构建产品A部分..." << std::endl;
    this->product_->SetParamA();
}

void ConcreteBuilder::BuildParamB()
{
    std::cout << "正在构建产品B部分..." << std::endl;
    this->product_->SetParamB();
}

void ConcreteBuilder::BuildParamC()
{
    std::cout << "正在构建产品C部分..." << std::endl;
    this->product_->SetParamC();
}

Product* ConcreteBuilder::GetProduct()
{
    return this->product_;
}